/**
 * @file src/Zuker.h
 *
 * @date 28-aug-2013
 *
 * @author Youri Hoogstrate
 * @author Lisa Yu
 *
 * @section LICENSE
 * yh-kt-fold can predict RNA 2D structures including K-turns.
 * Copyright (C) 2012-2013 Youri Hoogstrate
 *
 * This file is part of yh-kt-fold.
 *
 * yh-kt-fold is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * yh-kt-fold is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */



#include "main.h"
#include "Functions/library.h"



/**
 * @brief Implements the Zuker algorithm with additional motif-folding features.
 *
 * @section DESCRIPTION
 * This file contains the Zuker class.
 * The program implements the Zuker's minimum Gibbs free energy energy
 * model with Motifs/K-turns functionality for RNA secondary structure
 * prediction.
 *
 * @date 28-aug-2013
 */
class Zuker
{
	private:
		// Parameters
		int MINIMAL_HAIRPINLOOP_SIZE;
		
		// Objects
		ReadData   *data;												// All Gibbs free energy values from table(s)
		DotBracket *dotBracket;
		//MotifTree   motifs;
		
		std::string rna_sequence;
		
	public:
		// Initialize
		Zuker();
		~Zuker();
		
		void  setSequence(char arg_sequence[]);
		void  unsetSequence();
		void  setHairpinlen(int arg_hairpinlen);
		void  init();
		
		// Energy functions:
		void  energy_init();
		float v(int i, int j);
		float w(int i, int);
		void  GibbsFreeEnergy();										// Fills the V and W matrices
		
		// Energy per structure functions:
		float energyStack(int arg_i, int arg_j);
		float energyBulgeLoop(int i, int j, int ip, int jp);
		float energyHairpinLoop(int i, int j);
		float energyInternalLoop(int i, int j, int ip, int jp);
		float energyAuPenalty(char arg_n1, char arg_n2);
		float energyKTurn(int arg_i, int arg_j, int arg_ip, int arg_jp, TracebackMotif *arg_TracebackMotif, TracebackMotif **arg_TracebackMotif_p);
		float energy_motif_surrounding_stack(char arg_nucleotide5p, char arg_nucleotide3p);
		
		// ????????/ what does this do?:
		void  subSequence(int start, int len, char target[], bool forwards);
		bool  sequenceMatch(char motif[], char seq[]); 					// should this not be in a K-turn motif..!?!?!?!
		
		// Trace-back functions:
		void  traceback();
		void  tracebackPush(int i, int j, bool pick_from_v_path);
		bool  tracebackPop(int *i, int *j, bool *pick_from_v_path);
		
		// Trace-back (original) functions:
		void  tracebackOriginal();
		void  tracebackOriginalPush(int i, int j);
		bool  tracebackOriginalPop(int *i, int *j);
		
		
		// Output functions
		void  print2DStructure();										// Should be string returning function... "format2DStructure"
		
		//Debugging functions:
		void printWij();
		void printVij(bool replaceInf);
		void printPathMatrix();
		void printTypeMatrix();
		
		// Variables:
		char  rnaSequence[MAXLEN];
		int  *rnaSequenceEnumerated;
		int   rnaSequenceLength;
		
		float           Vij[MAXLEN][MAXLEN];
		float           Wij[MAXLEN][MAXLEN];
		TracebackMotif *Mij[MAXLEN][MAXLEN];							// Stores pointers to Tracebackotif objects; must become a tree object once
		Motif          *Nij[MAXLEN][MAXLEN];							// Stores pointers to Motif objects; must become a tree
};
